package server;

import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;

import user.User;
import util.Record;

public class Log {
	private File file;
	private String filePath;
	private Calendar cal;
	
	public Log(String filePath){
		this.file = new File(filePath);
		this.filePath = filePath;
		cal = Calendar.getInstance();
	}
	
	public void addLogEntry(User user, String event, String recNbr){
		String str = cal.getTime().toString() + " : " +  user.getName() + " : "
		+ event  + " : " + recNbr;
		FileWriter fstream;
		try {
			fstream = new FileWriter(file, true);
		     BufferedWriter out = new BufferedWriter(fstream);
		     out.append(str +"\n");
		     out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
   
	}
	
	public void printLog() throws IOException{
		FileInputStream fstream = new FileInputStream(filePath);
		DataInputStream in = new DataInputStream(fstream);
        while (in.available() !=0){                          
        	System.out.println (in.readLine());
        }
        in.close();
	}
	

}
